<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Project;
use DB;
use Auth;
use App\Bid;

use Gregwar\Captcha\CaptchaBuilder;//验证码

class IndexController extends Controller
{
    //
    public function index(){
      $pros = Project::where('status',1)->take(3)->get();
      return view('index',['pros'=>$pros]);
    }
    //我的账单
    public function myzd(){
      $user = Auth::user();
      //获取用户信息
      // dd($u);exit;
      $hks = DB::table('hks')->where('uid',$user->uid)->paginate(3);

       return view('myzd',['hks'=>$hks]);
    }
    //我的投资
    public function mytz(){
      //没有登录先登录
      if (!Auth::check()) {
        return redirect('auth/login');
      }
      $user = Auth::user();

      $bids = Bid::where('bids.uid',$user->uid)
      ->join('projects','bids.pid','=','projects.pid')
      ->whereIn('projects.status',[1,2,3])
      ->select('bids.*','projects.status')//选取bids的全部,和projects的status列
      ->get();
      //$bids = DB::table('bids')->where(['uid'=>$user->uid])->get();
      return view('mytz',['bids'=>$bids]);
   }

   public function mysy(){
     //如果没有登陆Auth::check()
     if (!Auth::check()) {
       return redirect('auth/login');
     }
     //获取登录信息$user = Auth::user()
     $user = Auth::user();
     $grow = DB::table('grows')->where('uid',$user->uid)->orderBy('gid','desc')->get();
     return view('mysy',['grow'=>$grow]);
   }

   public function middle(){
     echo '这里是控制器';

   }

   public function mini(){
    //  header('Content-type: image/jpeg');
    //  $builder = new CaptchaBuilder;
    //  $builder->build();
    //  $builder->save('out.jpg');
    //  $builder->output();

   }


}
